<?php
require('../kernel/config.php');
require(PATH_ABS.'/admin/login.php');
$a_conf = ABConf::getAll();
$o_tpl =  new ABTemplate('admin/index', 'resource');
$_MSize = $a_conf['maxsizefile'] * pow(1024,2); // maximum filesize (x MiB)
$_EFile = array_map('trim', explode(',', $a_conf['extallow']));// allowed extensions
$o_Dir = new ABDir(PATH_IMG);

if(ABApi::hasAction('get')){
	if(!$o_Dir->download(urldecode($_POST['get']))){
		$o_tpl->error = 'No Pudo Descargarse el archivo';
	}
}elseif(isset($_POST['delete'])){
	$o_tpl->adelete =  true;
	$o_tpl->pid=$_POST['delete'];
}elseif(isset($_POST['erase'])){
	if(!$o_Dir->delete($_POST['erase'])){
		$o_tpl->set('error', 'No Pudo Borrarse el archivo');
	}else{$o_tpl->set('ok', 'Archivo Borrado');}
}elseif(isset($_POST['submit'])){
	$i_response = $o_Dir->upload('file', $_EFile, $_MSize);
	if($i_response === 0){
		$o_tpl->set('ok', 'Archivo Subido');
	}else{
		$o_tpl->set('error','Hubo un error. '. $o_Dir->errorString($i_response));
	}
}
 
$o_tpl->maxsize = $_MSize;
$o_tpl->ext  = implode(', ' ,$_EFile);
$o_tpl->img = $o_Dir->ls();
$o_Dir->setDir(PATH_SCRIPT);
$o_tpl->scripts = $o_Dir->ls();
$o_tpl->ptitle = 'Recursos';
ABApi::setCommonAdmin($o_tpl);
$o_tpl->parse();
?>
